package com.cyd.adapter;

import java.util.List;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.cyd.bean.HomeBean;
import com.cyd.homefamily.R;
import com.cyd.util.ImageLoaderUtil;

public class RecyclerViewAdapter extends
		RecyclerView.Adapter<RecyclerViewHolder> {

	private List<HomeBean> mList;
	private ImageLoaderUtil imgUtil;
	private OnItemClickListener mOnItemClickListener;

	public RecyclerViewAdapter(List<HomeBean> mList) {
		super();
		this.mList = mList;
	}

	@Override
	public int getItemCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public void onBindViewHolder(RecyclerViewHolder holder, int position) {
		// TODO Auto-generated method stub
		imgUtil.disPlayImage(mList.get(position).getUrl(), holder.mImg);
		holder.mTitle.setText(mList.get(position).getTitle());
		holder.mMessage.setText(mList.get(position).getMessage());
	}

	@Override
	public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int position) {
		// TODO Auto-generated method stub
		LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(
				parent.getContext()).inflate(R.layout.item_home, null);
		imgUtil = ImageLoaderUtil.getInstance(parent.getContext());
		RecyclerViewHolder holder = new RecyclerViewHolder(linearLayout,
				mOnItemClickListener);
		return holder;
	}

	public interface OnItemClickListener {
		public void onItemClick(View v, int pos);
	}

	public void setOnItemClickListener(OnItemClickListener listener) {
		if (listener != null)
			mOnItemClickListener = listener;
	}

}
